package com.zxmzy.scaffold.core.net

import com.zxmzy.scaffold.core.net.error.ApiException

/**
 * @author zhangxiaoming
 * @date 2023/8/30
 * @description
 */
class RequestDSL<Response> {
    internal lateinit var request: suspend () -> Response
    internal var onStart: (() -> Boolean?)? = null
    internal var onResponse: ((Response) -> Unit)? = null
    internal var onError: ((ApiException) -> Boolean?)? = null
    internal var onFinally: (() -> Boolean?)? = null
    infix fun onStart(onStart: (() -> Boolean?)?) {
        this.onStart = onStart
    }

    infix fun onRequest(request: suspend () -> Response) {
        this.request = request
    }

    infix fun onResponse(onResponse: ((Response) -> Unit)?) {
        this.onResponse = onResponse
    }

    infix fun onError(onError: ((ApiException) -> Boolean?)?) {
        this.onError = onError
    }

    infix fun onFinally(onFinally: (() -> Boolean?)?) {
        this.onFinally = onFinally
    }
}